//判断app客户端
var ua = navigator.userAgent.toLowerCase();
var os = '';
if (/iphone|ipad|ipod/.test(ua)) {		   
	os = 'ios';
} else if (/android/.test(ua)) {		 
	os = 'android';
}
var informationid = getParameter("informationid");
var uid=getParameter("uid");
//获取url参数
function getParameter(param) {
	var query = window.location.search;
	var iLen = param.length;
	var iStart = query.indexOf(param);
	if (iStart == -1)
		return "";
	iStart += iLen + 1;
	var iEnd = query.indexOf("&", iStart);
	if (iEnd == -1)
		return query.substring(iStart);
	return query.substring(iStart, iEnd);
}

$(function(){
	var urlStr = serverPath + "/app/doctor/doctor/healthmessage.do";
	var jsonStr = '{method:"getMessageH",requestlist:[{ informationid:"'+informationid+'" }],  version:"1.0",uid:"'+uid+'", requestsource:"diabetes"}' ;
	UseAjax(urlStr, jsonStr, document.cookie, test, '1');
});

function test(nodeArrays){
	var nodeArray=nodeArrays.resultlist[0].resultlist;
	if (nodeArray && nodeArray.title && nodeArray.content) {
		$('#title').html(nodeArray.title);
		$('#dates').html(nodeArray.dates.substring(0,10));
		$('#content').html(nodeArray.content);
		$('#type').html(nodeArray.type);
		$('#readcount').html(nodeArray.readcount);
		
//		if(nodeArray.picurl!=null&&nodeArray.videoid==null){
//			//隐藏视频div
//			var style="display: none;"
//			var v = document.getElementById("video");
//			v.style.display="none";//隐藏释放页面空间
//			$('#image_url').attr('src',nodeArray.picurl);
//		}
		
		//初始化数据 关于页面的尺寸的设置
		var width = window.innerWidth-32;
		var height = width * 3 / 4;
		//height = height > window.innerHeight ? window.innerHeight : height;
		window.tvpSetting = {
			width : width,
			height : height,
		};
		//生产模式
//		var videoid = nodeArray.videoid;
		//调试模式
		var videoid="x0194s8n5rt";
		if(videoid!=null){
			
			//var videoid = nodeArray.videoid;
			//创建 tvp.VideoInfo 类（待播放的视频信息）的对象实例。
			var video = new tvp.VideoInfo();
			//视频vid，从腾讯视频V+上传得到。（点播视频）
			video.setVid(videoid);
			//创建 tvp.Player 类（播放器信息）的对象实例。
			var player =new tvp.Player();
//			var player = new tvp.Player(600, 450);
			//默认封面图
			player.create({
				  width  : tvpSetting.width,
				  height : tvpSetting.height,
				  pic    : tvp.common.getVideoSnapMobile(videoid),
				  video  : video,
				  modId  : 'video',
				  isContinuePlay: false,
				  autoplay: false,
				  playerType : 'html5',
				  isHtml5UseFakeFullScreen : false,
				 
				onplay: function () {
					if(os=='android'&& window.tkInterface!=undefined){
						player.pause();
						if ($('#android_video').html() == "") {
							$('#android_video').html($('#video').html());
							$('#android_video').find('.tvp_container').html("");
							$('#android_video').find('.tvp_container').append($('#video').find('.tvp_overlay_poster')[0]);
							$('#android_video').append('<div class="tvp_overlay_play"><span class="tvp_button_play"></span></div>');
							$('#android_video').find('.tvp_button_play').click(function(event) {
								callAndroidJs(video);
							});
							/*$('#android_video').attr('style', $('#android_video').attr('style')+$('#video').find('.tenvideo_player').attr('style'));
							$('#android_video').append('<div class="tvp_video"></div>');
							$('#android_video').find('.tvp_video').append('<img width="100%" height="100%" src="' + tvp.common.getVideoSnapMobile(videoid) + '" />');
							$('#android_video').find('.tvp_video').append('<div class="tvp_shadow"></div>');
							$('#android_video').append('<div class="tvp_overlay_play"><span class="tvp_button_play"></span></div>');
							$('#android_video').find('.tvp_button_play').click(function(event) {
								callAndroidJs(video);
							});*/
						}
						$('#video').hide();
						$('#android_video').show();
					}
		        },
		        onplaying: function () {
		        	if(os=='android'&& window.tkInterface!=undefined){
		        		player.pause();
		        	}
		        },
		        onresume: function () {
		        	if(os=='android'&& window.tkInterface!=undefined){
		        		player.pause();
		        	}
		        }
				});
		}
	}	
}

function callAndroidJs(video) {
	window.tkInterface.invokeMethod(video.url);
}

